package com.starlink.common.log;

import com.starlink.common.log.dto.UserInfo;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author: lichao
 * @date: 2021-06-22 14:52:59
 */
public class DefaultApplicationLogContext implements ApplicationLogContext, ApplicationContextAware {
    public final static ThreadLocal<UserInfo> USER_INFO_THREAD_LOCAL = new ThreadLocal<>();
    private ApplicationContext applicationContext;


    @Override
    public String getApplicationName() {
        return applicationContext.getEnvironment().getProperty("spring.application.name");
    }

    @Override
    public UserInfo getUserInfo() {
        return USER_INFO_THREAD_LOCAL.get();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
